﻿using B.S.Outsourcing.ErrorCode;
using B.S.Outsourcing.Infatructrue;
using B.S.Outsourcing.Writer.Api.Application.Command.OutsourcingArrivalOrderModel;
using MediatR;

namespace B.S.Outsourcing.Writer.Api.Application.CommandHandler.OutsourcingArrivalOrderModel
{
    public class DeleteOutSoutArrivalIDCommandHandler : IRequestHandler<DeleteOutSoutArrivalIDCommand, ApiResult<int>>
    {
        private readonly DBHelper1 dBHelper;

        public DeleteOutSoutArrivalIDCommandHandler(DBHelper1 dBHelper)
        {
            this.dBHelper = dBHelper;
        }

        public async Task<ApiResult<int>> Handle(DeleteOutSoutArrivalIDCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var sql = $"update OutsourcingArrivalOrderModel set IsDelete=1 where id={request.Id}";
            var str = dBHelper.NonQuery(sql);
            if (str > 0)
            {
                result.Code = ApiEnums.成功;
                result.Message = "成功";
                result.Data = str;
            }
            else
            {
                result.Code = ApiEnums.成功;
                result.Message = "成功";
                result.Data = str;
            }
            return await Task.FromResult(result);
        }
    }
}
